<template>
  <div class="index">
    <Location class="index-location" type="advertising" />
    <div class="index-advertising">
      <!-- 广告预算 -->
      <div class="index-advertising-form">
        <div class="index-advertising-form-label">广告预算</div>
        <div class="index-advertising-form-right">
          <el-radio-group v-model="field.formData.yusuan">
            <el-radio v-for="b in list.budgetList" :key="b.id" :label="b.id">{{
              b.title
            }}</el-radio>
          </el-radio-group>
        </div>
      </div>
      <!-- 广告周期 -->
      <div class="index-advertising-form">
        <div class="index-advertising-form-label">广告周期</div>
        <div class="index-advertising-form-right">
          <el-radio-group v-model="field.formData.year">
            <el-radio v-for="c in list.cycleList" :key="c.id" :label="c.id">{{
              c.title
            }}</el-radio>
          </el-radio-group>
        </div>
      </div>
      <!-- 公司名称 -->
      <div class="index-advertising-form">
        <div class="index-advertising-form-label">公司名称</div>
        <div class="index-advertising-form-input">
          <el-input
            v-model="field.formData.shop_name"
            placeholder="请输入您的公司名称"
          ></el-input>
        </div>
      </div>
      <!-- 企业类型 -->
      <div class="index-advertising-form">
        <div class="index-advertising-form-label">企业类型</div>
        <div class="index-advertising-form-select">
          <el-select
            v-model="field.formData.shop_type"
            placeholder="请选择您的企业类型"
          >
            <el-option
              v-for="t in list.typeList"
              :key="t.id"
              :value="t.id"
              :label="t.name"
            ></el-option>
          </el-select>
        </div>
      </div>
      <!-- 联系姓名 -->
      <div class="index-advertising-form">
        <div class="index-advertising-form-label">联系姓名</div>
        <div class="index-advertising-form-input">
          <el-input
            v-model="field.formData.member_name"
            placeholder="请输入您的姓名"
          ></el-input>
        </div>
      </div>
      <!-- 联系电话 -->
      <div class="index-advertising-form">
        <div class="index-advertising-form-label">联系电话</div>
        <div class="index-advertising-form-input">
          <el-input
            v-model="field.formData.member_phone"
            placeholder="请输入您的联系电话"
          ></el-input>
        </div>
      </div>
      <!-- 备注内容 -->
      <div class="index-advertising-startform">
        <div class="index-advertising-form-label">备注内容</div>
        <div class="index-advertising-form-collect">
          <div class="index-advertising-form-text">
            <el-input
              v-model="field.formData.beizhu"
              placeholder="请输入您的备注内容"
              type="textarea"
              rows="8"
              resize="none"
              size="medium"
            ></el-input>
          </div>
          <div class="index-advertising-form-group">
            <div
              class="index-advertising-form-confirm"
              @click="field.handleApplyAdvertisement"
            >
              立即提交
            </div>
            <div
              class="index-advertising-form-reset"
              @click="field.handleReset"
            >
              重置
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ToastBottom, setObj, getObj } from "@/utils/index";
import { onMounted, computed, ref, reactive, toRefs, inject } from "vue";
import { useRoute, useRouter } from "vue-router";
import Location from "@/components/location/index";
import { ElMessage } from "element-plus";

//获取路由
const $_route = useRoute();
const $_router = useRouter();
//获取接口
const $_api = inject("$api");
onMounted(() => {
  //获取广告页面
  api.getAdvertisementYe();
});
//联系我们
const api = reactive({
  //获取广告页面
  getAdvertisementYe: async () => {
    const results = await $_api.advertisementYe();
    if (results && results.status > 0) {
      list.budgetList = results.data.yusuan;
      list.cycleList = results.data.year;
      list.typeList = results.data.shop_type;
    }
  },
  //广告申请
  postAdvertisement: async () => {
    const results = await $_api.advertisement(field.formData);
    if (results && results.status > 0) {
      ElMessage.success(results.info);
    }
    field.handleReset();
  },
});
const list = reactive({
  // 广告预算
  budgetList: [],
  // 广告周期
  cycleList: [],
  // 企业类型
  typeList: [],
});
const field = reactive({
  formData: {
    yusuan: "",
    year: "",
    shop_name: "",
    shop_type: "",
    member_name: "",
    member_phone: "",
    beizhu: "",
  },
  handleApplyAdvertisement: () => {
    api.postAdvertisement();
  },
  handleReset: () => {
    field.formData.yusuan = "";
    field.formData.year = "";
    field.formData.shop_name = "";
    field.formData.shop_type = "";
    field.formData.member_name = "";
    field.formData.member_phone = "";
    field.formData.beizhu = "";
    api.getAdvertisementYe();
  },
});
</script>

<style lang="scss" scoped>
.index {
  @include flex(flex-start, center);
  flex-direction: column;
  margin: 5px auto 0;
  width: 1200px;
}
.index-location {
  flex-shrink: 0;
  width: 100%;
  height: 105px;
}
.index-advertising {
  @include flex(flex-start, flex-start);
  flex-direction: column;
  margin-top: 13px;
  margin-bottom: 20px;
  width: 100%;
}
.index-advertising-form {
  @include flex(flex-start, center);
  margin-bottom: 20px;
}
.index-advertising-startform {
  @include flex(flex-start, flex-start);
  .index-advertising-form-label {
    margin-top: 5px;
  }
}
.index-advertising-form-label {
  width: 100px;
  text-align: left;
  font-size: 18px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 25px;
}
.index-advertising-form-right {
  font-size: 18px;
}
.index-advertising-form-input {
  width: 533px;
  height: 40px;
  background: #f4f4f4;
  opacity: 0.79;
}
.index-advertising-form-select {
  width: 533px;
  height: 40px;
  background: #f4f4f4;
  opacity: 0.79;
}
.index-advertising-form-collect {
  @include flex(flex-start, center);
  flex-direction: column;
  width: 533px;
}
.index-advertising-form-text {
  width: 533px;
  height: 173px;
  background: #f4f4f4;
  opacity: 0.79;
  overflow: hidden;
}
.index-advertising-form-group {
  @include flex(flex-start, center);
  margin-top: 20px;
  width: 100%;
}
.index-advertising-form-confirm {
  margin-right: 67px;
  flex-shrink: 0;
  flex-grow: 1;
  height: 36px;
  line-height: 36px;
  text-align: center;
  background: #df7935;
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  cursor: pointer;
}
.index-advertising-form-reset {
  flex-shrink: 0;
  flex-grow: 1;
  height: 36px;
  line-height: 36px;
  text-align: center;
  background: #e1e1e1;
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #6d6d6d;
  cursor: pointer;
}
</style>
<style lang="scss" scoped>
.index-advertising-form-right :deep(.el-radio) {
  margin-right: 20px;
}

.index-advertising-form-input :deep(.el-input__inner) {
  border-radius: 0;
  border: none;
  background: #f4f4f4;
  &::placeholder {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #9e9e9e;
    line-height: 22px;
  }
}
.index-advertising-form-select :deep(.el-input__inner) {
  border-radius: 0;
  border: none;
  background: #f4f4f4;
  &::placeholder {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #9e9e9e;
    line-height: 22px;
  }
}
.index-advertising-form-select :deep(.el-select) {
  width: 100%;
}
.index-advertising-form-text :deep(.el-textarea__inner) {
  width: 100%;
  border-radius: 0;
  border: none;
  background: #f4f4f4;
  &::placeholder {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #9e9e9e;
    line-height: 22px;
  }
}
</style>
